// 拼后台传过来的listjson并插入到表格中
function updateList(data){
    var dataL = data.length;
    var html = "";
    for(var i = 0; i < dataL; i++){
        html = html + "<tr>"
            +  "<td>" + zhigong.undefinedHandler(data[i].ygbh) + "</td>"
            +  "<td>" + zhigong.undefinedHandler(data[i].xm) + "</td>"
            +  "<td>" + zhigong.undefinedHandler(data[i].sj) + "</td>"
            +  "<td>" + zhigong.undefinedHandler(data[i].dh) + "</td>"
            +  "<td>" + zhigong.undefinedHandler(data[i].bmmc) + "</td>"
            +  "<td>" + zhigong.undefinedHandler(data[i].zwmc) + "</td>"
            +  "<td>"
            +  "<a href=\"javascript:zhigong.openModal('yuangong','view'," + data[i].ygbh  +")\" class=\"btn btn-primary btn-xs btn-margin\" >查看</a>"
            +  "<a href=\"javascript:zhigong.openModal('yuangong','update'," + data[i].ygbh + ")\" class=\"btn btn-info btn-xs btn-margin\">修改</a>"
            +  "<a href=\"javascript:zhigong.deleteData('yuangong', " + data[i].ygbh + ")\" class=\"btn btn-danger btn-xs btn-margin\">删除</a>"
            +  "</td>"
            +"</tr>";
    }

    var tbodyList = $("#tbodyList");
    tbodyList.html(html);
}
$(function(){

    // 返回部门列表
    $.ajax({
        url: zhigong.URL.urlNoParam('bumen'),
        type: "GET",
        dataType: "json",
        data: {
            pageNumber : -1
        },
        contentType: "application/json;charset=UTF-8",
        success: function (result) {
            var resData = result.data;
            var dataL = resData.length;
            var html = "";
            for(var i = 0; i < dataL; i++){
                html = html + "<option value="+ resData[i].bmbh +">"+ resData[i].mc +"</option>>";
            }
            $("#bmbh").html(html);
        },
        error: function (result) {
            var message = JSON.stringify(result);
            console.log("error:" + message);
        }
    })

    // 返回职位列表
    $.ajax({
        url: zhigong.URL.urlNoParam('zhiwei'),
        type: "GET",
        dataType: "json",
        data: {
            pageNumber : -1
        },
        contentType: "application/json;charset=UTF-8",
        success: function (result) {
            var resData = result.data;
            var dataL = resData.length;
            var html = "";
            for(var i = 0; i < dataL; i++){
                html = html + "<option value="+ resData[i].zwbh +">"+ resData[i].mc +"</option>>";
            }
            $("#zwbh").html(html);
        },
        error: function (result) {
            var message = JSON.stringify(result);
            console.log("error:" + message);
        }
    })

    // 初始化加载列表数据
    zhigong.pageData("yuangong", 1, true);

    // 日期控件初始化中文
    !function(a){a.fn.datepicker.dates["zh-CN"]={days:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],daysShort:["周日","周一","周二","周三","周四","周五","周六"],daysMin:["日","一","二","三","四","五","六"],months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],monthsShort:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],today:"今日",clear:"清除",format:"yyyy-mm-dd",titleFormat:"yyyy-mm",weekStart:1}}(jQuery);

    $('.form-datepicker').datepicker({
        clearBtn: true,
        language: "zh-CN",
        autoclose: true,
        todayHighlight: true
    });
})